﻿@using Jugg.Mapping.Category
@model IEnumerable<CategoryMapping>
@{
    ViewBag.Title = "功能模块";
}
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="@Url.RouteUrl("homeIndex")">首页</a>
        </li>
        <li class="active">@ViewBag.Title</li>
    </ul>
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            @ViewBag.Title
            <small>
                <i class="ace-icon fa fa-angle-double-right"></i>
            </small>
        </h1>
    </div>

    <style>
        .fr {
            float: right;
        }
    </style>


    @if (Model != null)
    {
        var lookupList = Model.Where(o => o.FatherResource == null).ToList();

        <div class="row">
            <div class="col-sm-12">
                @foreach (var item in lookupList)
                {
                    <div class="widget-box col-sm-4">
                        <div class="widget-body">
                            <div class="widget-main padding-8">
                                <div class="tree tree-selectable">
                                    @RenderCategory(item, Model)
                                </div>
                            </div>
                        </div>
                    </div>
                }
            </div>
        </div>
    }
    @helper RenderCategory(CategoryMapping item, IEnumerable<CategoryMapping> list)
    {
var childList = list.Where(o => o.FatherResource == item.SysResource).ToList();
    <div class="tree-folder" style="display: block;">

        @if (childList != null && childList.Any())
        {
            <div class="tree-folder-header">
                <i class="ace-icon tree-minus"></i>
                <div class="tree-folder-name">@item.Name</div>
                @if (!item.IsDisabled)
                {
                    <i class="ace-icon fa fa-check bigger-110 green" title="已启用"></i>
                    <a href="@Url.RouteUrl("disabledOrEnabled",new { id = item.Id })" class="btnStartDisabled fr">停用</a>
                }
                else
                {
                    <i class="ace-icon fa fa-times bigger-110 red"></i>
                    <a href="@Url.RouteUrl("disabledOrEnabled",new { id = item.Id })" class="text-danger btnStartDisabled fr">启用</a>
                }
            </div>
            <div class="tree-folder-content" style="display: block;">
                @foreach (var child in childList)
                {
                    @RenderCategory(child, list);
                }
            </div>
        }
        else
        {
            <div class="tree-item" style="display: block;">
                <div class="tree-item-name">@item.Name</div>
                @if (!item.IsDisabled)
                {
                    <i class="ace-icon fa fa-check bigger-110 green" title="已启用"></i>
                    <a href="@Url.RouteUrl("disabledOrEnabled",new { id = item.Id })" class="btnStartDisabled fr">停用</a>
                }
                else
                {
                    <i class="ace-icon fa fa-times bigger-110 red"></i>
                    <a href="@Url.RouteUrl("disabledOrEnabled",new { id = item.Id })" class="text-danger btnStartDisabled fr">启用</a>
                }
            </div>
        }
    </div>
}

    <script>
        $(function () {
            $('.btnStartDisabled').click(function (e) {
                e.preventDefault();
                var _href = this.href;
                $.modal.confirm('你确定要执行此操作？', function () {
                    $.get(_href, function (data) {
                        $.modal.gritter(data, function () {
                            $.modal.reload();
                        });
                    });
                });
            });
        });
    </script>


</div>








